package com.markerhub.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.markerhub.entity.Message;
import com.markerhub.entity.User;
import com.markerhub.mapper.MessageMapper;
import com.markerhub.mapper.UserMapper;
import com.markerhub.service.MessageService;
import com.markerhub.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 关注公众号：MarkerHub
 * @since 2021-04-10
 */
@Service
public class MessageServiceImpl extends ServiceImpl<MessageMapper, Message> implements MessageService {

    @Autowired
    MessageMapper messageMapper;

    //增加留言
    @Override
    public void addMessage(String time,String messageContent,String avatar,String nickname)
    {
        Message message=new Message();
        Date data=new Date();
        ZoneId zoneId = ZoneId.systemDefault();
        LocalDateTime localDateTime = LocalDateTime.ofInstant(data.toInstant(), zoneId);
        message.setTime(time);
        message.setMessageContent(messageContent);
        message.setAvatar(avatar);
        message.setNickname(nickname);
        message.setCreateTime(localDateTime);
        messageMapper.insert(message);
    }

    //获得留言列表
    @Override
    public List<Message> getMessageList()
    {
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.orderByAsc("create_time");
        return messageMapper.selectList(queryWrapper);
    }
}
